package com.client.ryt.task.http.response;


import com.client.ryt.basic.BaseResponse;
import com.client.ryt.entity.biz.ShopMember;
import com.client.ryt.entity.exception.JsonException;
import com.client.ryt.entity.exception.RemoteDataException;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * Created by Administrator on 2014/7/12.
 */
public class LoginResponse extends BaseResponse {

    private String token;
    private ShopMember shopMember;

    public LoginResponse(){super(null);}
    public LoginResponse(JSONObject json) {
        super(json);
        try {
            if(this.getIsSuccess()){
                JSONObject msg = json.getJSONObject("msg");
                this.token = msg.getString("token");
                if(msg.has("data")) {
                    JSONObject jo = msg.getJSONObject("data");
                    shopMember = new ShopMember();
                    shopMember.setId(jo.getLong("id"));
                    shopMember.setUid(jo.getLong("uid"));
                    shopMember.setShop_id(jo.getLong("shop_id"));
                    shopMember.setUsername(jo.getString("username"));
                    shopMember.setNickname(jo.getString("nickname"));
                    shopMember.setToken(jo.getString("token"));
                    shopMember.setShopname(jo.getString("shopname"));
                }
            }else{
                this.setBaseException(new RemoteDataException(json));
            }
        } catch (JSONException e) {
            this.setBaseException(new JsonException(e.getMessage()));
        }
    }

    public String getToken() {
        return token;
    }


    public ShopMember getShopMember() {
        return shopMember;
    }
}
